package script.db

databaseChangeLog(logicalFilePath: 'script/db/hpfm_cusz_view.groovy') {

    def weight = 1
    if (helper.isOracle()) {
        weight = 3
    }
    if (helper.isSqlServer()) {
        weight = 2
    }

    changeSet(author: "hzero@hand-china.com", id: "hpfm_cusz_view-2022-09-16") {
        if (helper.dbType().isSupportSequence()) {
            createSequence(sequenceName: 'hpfm_cusz_view_s', startValue: "1")
        }
        createTable(tableName: "hpfm_cusz_view", remarks: "租户级个性化视图") {
            column(name: "id", type: "bigint", autoIncrement: true, remarks: "表ID，主键，供其他表做外键") { constraints(primaryKey: true) }
            column(name: "code", type: "varchar(" + 120 * weight + ")", remarks: "功能编码") { constraints(nullable: "false") }
            column(name: "view_type", type: "varchar(" + 30 * weight + ")", defaultValue: "TABLE_VIEW", remarks: "视图类型，值集:HPFM.CUSZ.VIEW_TYPE") { constraints(nullable: "false") }
            column(name: "view_name", type: "varchar(" + 30 * weight + ")", remarks: "视图名称") { constraints(nullable: "false") }
            column(name: "data_json", type: "longtext", remarks: "数据")
            column(name: "default_flag", type: "tinyint", defaultValue: "1", remarks: "默认标志") { constraints(nullable: "false") }
            column(name: "menu_id", type: "bigint", remarks: "菜单ID")
            column(name: "tenant_id", type: "bigint", defaultValue: "0", remarks: "租户ID") { constraints(nullable: "false") }
            column(name: "created_by", type: "bigint", defaultValue: "-1", remarks: "创建人") { constraints(nullable: "false") }
            column(name: "last_updated_by", type: "bigint", defaultValue: "-1", remarks: "最近更新人") { constraints(nullable: "false") }
            column(name: "creation_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "创建时间") { constraints(nullable: "false") }
            column(name: "last_update_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "最近更新时间") { constraints(nullable: "false") }
            column(name: "object_version_number", type: "bigint", defaultValue: "1", remarks: "行版本号，用来处理锁") { constraints(nullable: "false") }
        }

        createIndex(tableName: "hpfm_cusz_view", indexName: "hpfm_cusz_view_n1") {
            column(name: "code")
            column(name: "tenant_id")
        }
    }
}
